<?php 
/**
 *   Kaltura Browser - components/com_kaltura/views/browser/tmpl/default.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Author: Miguel Puig Garcia (miguel@bittingbits.com)
 *   Copyright (C) 2011 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access'); 
jimport('joomla.utilities.date');
?>
<div id="kaltura">
    <div id="kalturasearch">
        <span class="searchbox"><input type="text" name="searchfield" id="searchfield" /></span>
        <span class="buttonbox"><input type="submit" id="searchstart" value="<?php echo JText::_('KALTURA_SEARCH'); ?>"/></span>
    </div>
    <div id="kalturabrowser">
        <div id="filtersarea">
            <div id="boxtab1" class="boxtab">
                <div class="boxtab-header">
                    <?php echo JText::_('KALTURA_ADDITIONAL_FILTERS'); ?>
                </div>
                <div id="boxtab1-content" class="boxtab-content">
                    <div>
                        <div class="filter_all selected" id="durationall">
                            <?php echo JText::_('KALTURA_DURATIONS'); ?>
                        </div>
                        <ul>
                            <li class="duration" id="durationshort"><?php echo JText::_('KALTURA_SHORT'); ?></li>
                            <li class="duration" id="durationmedium"><?php echo JText::_('KALTURA_MEDIUM'); ?></li>
                            <li class="duration" id="durationlong"><?php echo JText::_('KALTURA_LONG'); ?></li>
                        </ul>
                    </div>
                    <div>
                        <div class="filter_all selected" id="mediatypeall">
                            <?php echo JText::_('KALTURA_ALL_MEDIA_TYPES'); ?>
                        </div>
                        <ul>
                            <li class="mediatype" id="video"><?php echo JText::_('KALTURA_VIDEO'); ?></li>
                            <li class="mediatype" id="audio"><?php echo JText::_('KALTURA_AUDIO'); ?></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div id="boxtab2" class="boxtab">
                <div class="boxtab-header">
                    <?php echo JText::_('KALTURA_CATEGORIES'); ?>
                </div>
                <div id="boxtab2-content" class="boxtab-content">
                    <?php
                    print_categories($this->categories);
                    ?>
                </div>
            </div>
        </div>
        <div id="resultsarea">

                <table>
                    <!--<thead>
                        <th width="32"><?php echo JText::_('KALTURA_THUMB'); ?></th>
                        <th><?php echo JText::_('KALTURA_NAME'); ?></th>
                        <th><?php echo JText::_('KALTURA_DURATION'); ?></th>
                    </thead>-->
                      <thead>
					    <tr>
					      <th colspan="3" class="pagination"><?php echo JText::_('KALTURA_LISTOFVIDEOS'); ?></th>

					    </tr>
					  </thead>
  
					<tfoot>
					    <tr>
					      <td colspan="3" class="pagination">
						 		<span class="paginator" id="first"><?php echo JText::_('KALTURA_FIRST'); ?></span>
						        <span class="paginator" id="prev"><?php echo JText::_('KALTURA_PREV'); ?></span>
						        <span id="actualpage" value="1">1</span> /
						        <span id="totalpages" value="<?php echo $this->totalpages; ?>" >
						            <?php echo $this->totalpages; ?>
						        </span>
						        <span class="paginator <?php echo ((1<$this->totalpages)?'enabled':''); ?>" id="next">
						            <?php echo JText::_('KALTURA_NEXT'); ?>
						        </span>
						        <span class="paginator <?php echo ((1<$this->totalpages)?'enabled':''); ?>" id="last">
						            <?php echo JText::_('KALTURA_LAST'); ?>
						        </span>      
					      </td>
					    </tr>
					  </tfoot>
					                    
                    <tbody id="table_tbody">
                    
                    </tbody>
                </table>

        </div>
    </div>
    
    <input type="hidden" name="tableid" id="tableid" value="<?php echo JRequest::getVar('tableid'); ?>" />
    <input type="hidden" name="page" id="page" value="1" />
    <input type="hidden" name="tpages" id="tpages" value="<?php echo $this->totalpages; ?>" />
    
    <div style="display:none;">
    <div id="sqbox" class="modal"></div>
    </div>
    <div class="msgcont">
        <div id="loadingbox" class="notvisible"><?php echo JText::_('KALTURA_LOADING'); ?></div>
    </div>
</div>

<?php
function print_categories($categories, $level=0) {
    if ($level==0) echo '<div class="category selected" id="categoriesall">All</div>';
    foreach ($categories as $cat) {
        echo '<div class="category level'.$level.'" id="'.$cat->id.'">';
        for ($i = 0; $i < $level+1; $i++) echo "&nbsp;&nbsp;&nbsp";
        if (!empty($cat->children)) echo '<b>';
        echo $cat->name;
        echo '<input type="hidden" name="parent" id="parent'.$cat->id.'" value="'.$cat->parent.'" />';
        echo '</div>';
        if (!empty($cat->children)) echo '</b>';
        
        if (!empty($cat->children)) {
            echo '<div class="childrenbox" id="children'.$cat->id.'">';
            print_categories($cat->children, $level+1);
            echo '</div>';
        }
    }
}
?>
